window.onload = function(){
	document.getElementById("btn").onclick = function(){
		var input_name = document.getElementById("input_name").value;
		var input_sex = document.getElementById("input_sex").value;
		var input_age = document.getElementById("input_age").value;
		
		var td_check = document.createElement("td");
		var check = document.createElement("input");
		check.setAttribute("type","checkbox");
		check.setAttribute("name","cb");
		td_check.appendChild(check);
		
		var td_name = document.createElement("td");
		var text_name = document.createTextNode(input_name);
		td_name.appendChild(text_name);
		
		var td_sex = document.createElement("td");
		var text_sex = document.createTextNode(input_sex);
		td_sex.appendChild(text_sex);
		
		var td_age = document.createElement("td");
		var text_age = document.createTextNode(input_age);
		td_age.appendChild(text_age);
		
		var td_a = document.createElement("td");
		var a_del = document.createElement("a");
		a_del.setAttribute("href","javascript:void(0)");
		a_del.setAttribute("onclick","del(this)");
		var del = document.createTextNode("删除");
		a_del.appendChild(del);
		td_a.appendChild(a_del);
		
		var tr = document.createElement("tr");
		tr.appendChild(td_check);
		tr.appendChild(td_name);
		tr.appendChild(td_sex);
		tr.appendChild(td_age);
		tr.appendChild(td_a);
		
		var table = document.getElementsByTagName("table")[0];
		table.appendChild(tr);
	}
	
	//全选事件
	document.getElementById("selectAll").onclick = function(){
		var cbs = document.getElementsByName("cb");
		for (var i = 0; i < cbs.length; i++) {
			cbs[i].checked = true;
		}
	}
	
	//全不选事件
	document.getElementById("selectAll_no").onclick = function(){
		var cbs = document.getElementsByName("cb");
		for (var i = 0; i < cbs.length; i++) {
			cbs[i].checked = false;
		}
	}
	
	//反选事件
	document.getElementById("select_reverse").onclick = function(){
		var cbs = document.getElementsByName("cb");
		for (var i = 0; i < cbs.length; i++) {
			if(cbs[i].checked == true){
				cbs[i].checked = false;
			}else{
				cbs[i].checked = true;
			}
		}
	}
	
	//全选或全不选单选框
	document.getElementById("first_cb").onclick = function(){
		var cbs = document.getElementsByName("cb");
		for (var i = 0; i < cbs.length; i++) {
			cbs[i].checked = this.checked;
		}
	}
	
	var trs = document.getElementsByTagName("tr");
	for (var i = 0; i < trs.length; i++) {
		trs[i].onmouseover = function(){
			this.className = "tr_over";
		}
		trs[i].onmouseout = function(){
			this.className = "tr_out";
		}
	}
}

//删除事件
function del(obj){
	var table = obj.parentNode.parentNode.parentNode;
	var tr = obj.parentNode.parentNode;
	table.removeChild(tr);
}